package com.yc.http.d0706;

public class SessionServlet extends HttpServlet {

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException {
        HttpSession session = request.getSession();
        String value = (String) session.getAttribute("name");
        response.getWriter().append("sessionId = " + session.getId() + "<br>");
        response.getWriter().append("name = " + value + "<br>");

        // value == null 表示第一次访问服务器
        if (value == null) {
            session.setAttribute("name","zhangsan");
        }
    }
}
